<template>
  <div className="app-container">
    <div className="table-container">
      <base-list
        ref="table"
        url="/medal_info"
        :options="options"
        :columns="columns"
        :format="format"
        :rules="rules"
        permission="ADMIN"
        @reloadOptions="handleGetOptions"
      >
        <template slot="raw_actions" slot-scope="scope">
          <el-button v-waves type="success" class="filter-button" icon="el-icon-list" style="margin-left: 10px" @click="copy(scope.row, scope.$index)">复制
          </el-button>
        </template>
      </base-list>
    </div>
  </div>
</template>

<script>
import {getBaseDetail, getBaseList, getBaseOptions, requestBase} from '@/api/common'
import BaseList from '@/components/BaseList/index.vue'
import {deepClone} from "@/utils";

export default {
  name: 'medaInfo',
  components: {BaseList},
  data() {
    return {
      columns: [
        {show: true, edit: false, width: '100', key: 'id', fixed: true, label: 'ID', tooltip: 'ID', type: 'NUMBER', queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'name', label: '名称', tooltip: '名称', type: 'WORD', queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'groupFirst', label: '一级分组', tooltip: '一级分组', type: 'WORD', queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'sortByFirst', label: '一级排序', tooltip: '一级排序', type: 'NUMBER', queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'groupSecond', label: '二级分组', tooltip: '二级分组', type: 'WORD', queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'sortBySecond', label: '二级排序', tooltip: '二级排序', type: 'NUMBER', queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'description', label: '描述', tooltip: '描述', type: 'WORD', queryable: true},
        {show: true, edit: true, width: 'auto', minWidth: '100', key: 'image', label: '图片', tooltip1: '图片', type: 'IMAGE', imageSuffix: 'medal-' },
        {show: false, edit: true, width: 'auto', minWidth: '200', key: 'scripConditions', label: 'SCRIPT规则条件', tooltip1: 'SCRIPT规则条件', type: 'LONG_WORD', rows: 5 },
        {show: false, edit: true, width: 'auto', minWidth: '200', key: 'sqlConditions', label: 'SQL规则条件', tooltip1: 'SQL规则条件', type: 'LONG_WORD', rows: 5 },
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'entity', label: '规则数据', tooltip: '规则数据', type: 'DICTIONARY', optionKey: 'entityOptions',queryable: true},
        {show: false, edit: true, width: 'auto', minWidth: '200', key: 'ruleConditions', label: 'JSON规则条件', tooltip1: 'JSON规则条件', type: 'LONG_WORD', rows: 5 },
        {show: true, edit: true, width: 'auto',minWidth: '200', key: 'ruleNumberValue', label: '达到数量', tooltip: '达到数量', type: 'NUMBER'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createTime', label: '创建时间', tooltip: '创建时间', type: 'DATE_TIME'},
        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'updateTime', label: '更新时间', tooltip: '更新时间', type: 'DATE_TIME', queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createUser', label: '创建人', tooltip: '创建人', type: 'WORD'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'updateUser', label: '修改人', tooltip: '修改人', type: 'WORD'},
      ],
      format: {},
      rules: {
        add: {

        },
        edit: {
          id: [{required: true, message: '请选择数据!', trigger: 'change'}],
        }
      },
      options: {
        entityOptions: [
          {id: 'BOOK', name: '用户图书'},
          {id: 'FEELING', name: '用户笔记'},
          {id: 'FEELING_LIKE', name: '用户笔记点赞'},
          {id: 'FEELING_FAVORITE', name: '用户笔记收藏'},
          {id: 'JOINTLY', name: '用户参加共读'},
          {id: 'JOINTLY_FEELING', name: '用户共读话题'},
          {id: 'JOINTLY_VOTE', name: '用户共读话题投票'},
          {id: 'JOINTLY_LIKE', name: '用户共读话题点赞'},
          {id: 'JOINTLY_FAVORITE', name: '用户共读话题收藏'},
        ]
      }
    }
  },

  created() {
    this.handleGetOptions()
  },
  mounted() {
  },
  methods: {
    handleGetOptions() {
      const options = JSON.parse(localStorage.getItem('allOptions'))
      if (options) {
        this.options = Object.assign(this.options, options)
      }
    },
    copy(row, index) {
      getBaseDetail('/medal_info', row.id).then(res => {
        const temp = res.data
        temp.id = null
        this.$nextTick(() => {
          this.$refs.table.temp = temp
        })
        this.$refs.table.handleAdd()
      }).catch(() => {
        this.$refs.table.handleAdd()
        const temp = deepClone(row)
        temp.id = null
        this.$nextTick(() => {
          this.$refs.table.temp = temp
        })
      })
    }
  }
}
</script>


